<?php
require_once 'BaseMySQLDAO.php';

class TelcoPromotionDAO extends BaseMySQLDAO {

    public function __construct($context) {
        parent::__construct($context, 'app');
    }
	
    public function getTelcoPromotion() {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');

            $inSQL = "	SELECT * 
            			FROM telco_promotion
            			ORDER BY `id` DESC
            		";
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function insertTelcoPromotion($param) {
        $result = null;
        try {
            $inSQL = "INSERT INTO
                        telco_promotion(id, detail, telco, status)
                        VALUES (
                           :id, :detail, :telco, :status
                        )";
            $queryParam = array(
                                ':id' => NULL,
                                ':detail' => $param['detail'],
                                ':telco' => $param['telco'],
                                ':status' => 1
                            );
            
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
	public function updateTelcoPromotion($param) {
        $result = null;
        try {
            $inSQL = "UPDATE telco_promotion SET
                                    detail = :detail,
                                    telco = :telco,
                                    status = :status
                        WHERE id = :id
                        ";
            $queryParam = array(
                                ':id' => $param['id'],
                                ':detail' => $param['detail'],
                                ':telco' => $param['telco'],
                                ':status' => $param['status']
                            );
            
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
	public function deleteTelcoPromotion($id) {
        try {

            $inSQL = "   DELETE FROM telco_promotion WHERE id = :id ";
            $queryParam = array(':id' => $id);
			
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
            return false;
        }
        return true;
    }
}
?>